<?	
if ($func == 'search')
{
	$hotel_search_fields					= array();
	
	$hotel_search_fields['hotel_price']		= $hotel_tour_price;
	$hotel_search_fields['hotel_name']		= $txt_hotel_name;		
	$hotel_search_fields['hotel_country']	= $sbo_hotel_country;
	$hotel_search_fields['hotel_location']	= $sbo_hotel_location;
	$hotel_search_fields['hotel_star']		= $txt_hotel_star;
	$_SESSION['hotel_search_fields'] 		= $hotel_search_fields;
	
	$qprice			= "";
	$qname			= "";
	$qlocation		= "";
	$qstar			= "";
}

$hotels = array();

$selects = array('a.*');
$from = array();
$from['table_name'] = 'hotel';
$from['alias'] 		= 'a';
$froms = array();
$froms[] = $from;

$from = array();
$from['table_name'] = 'currency';
$from['alias'] 		= 'cur';

$from = array();
$from['table_name'] = 'room';
$from['alias'] 		= 'ro';

if ($sbo_hotel_price != 0) {
	$price = new PriceSection();
	$price->select($sbo_hotel_price);
	//$qprice 		= " AND a.price >= 500000 AND a.price <= 1000000 ";
	$qprice_1 = array('AND', '(SELECT min(price) FROM room WHERE hotel_id = a.id)', '>=', $price->getmin_value());
	$qprice_2 = array('AND', '(SELECT max(price) FROM room WHERE hotel_id = a.id)', '<=', $price->getmax_value());
}

if ($txt_hotel_star != 0) {
	$qstar = array("AND", "a.star", "=", $txt_hotel_star);
}

if ($txt_hotel_name != '') {
	$qname = array("AND", "a.name", "LIKE", "'%".$txt_hotel_name."%'");
}

$hotel_search_fields['hotel_country']	= $sbo_hotel_country;

if ($txt_hotel_location != 0) {
	$qlocation = array("AND", "a.location", '=', $sbo_hotel_location);
} else if ($txt_hotel_country != 0) {
	$country = new Country();
	$coutry->select($sbo_hotel_country);
	if ($country)
	{
		$str_search = '';
		$locations = $country->getAllLocations();
		$cnt = 0;
		foreach ($locations as $location)
		{
			$cnt ++;
			if ($cnt != 1)
				$str_search .= ',';
			$str_search .= $location->getid();
		}
		$qlocation = array("AND", "a.location", "IN", "(".$str_search.")");
	}
}

$where_clause = array(array(null, 'a.active', '=', 1), $qname, $qprice, $qlocation, $qstar);

// COUNT total
$hotels_temp = Database::doQuery($selects, $froms, null, $where_clause);

$page		=	$page + 0;
$perpage	=	10;
$sum		=	sizeof($hotels_temp);
$pages		=	($sum-($sum%$perpage))/$perpage;
if ($sum % $perpage <> 0 )	$pages = $pages+1;
$page		=	($page==0)?1:(($page>$pages)?$pages:$page);
$min 		= 	abs($page-1) * $perpage;
$max 		= 	$perpage;

// To search hotel.
$hotels_temp	= 	Database::doQuery($selects, $froms, null, $where_clause, null, null, array($min,$max));

foreach ($hotels_temp as $hotel_temp)
{
	$hotel = new Tour();
	$hotel->select($hotel_temp['id']);
	$hotels[] = $hotel;
}

?>
<div class='tour_left'>
	<div class='title_1 cufon' style='width:595px;'>
        Kết quả tìm kiếm
    </div>
	<div class='wrap_tour_content'>
    	<div class='search_content'>
            <? include('z_includes/hotel_search.php'); ?>
        </div>
	    <? include('z_includes/hotel_filter.php'); ?>
		<div class='hotel_list' id='load_hotel'>
        	<? include('z_includes/hotel_list.php'); ?>
        </div>
    </div>
</div>

<div class='tour_right'>
<?
include('z_includes/hotel_right.php');
?>
</div>
<div style='clear:both'></div>